#
MODULE_NAME = _foo

#
CC   = gcc
CXX  = g++
DLLWRAP = dllwrap
RM = rm -vf

#
PYTHON_DIR = D:\Progs\Python25

LIBS = -L"$(PYTHON_DIR)\libs" -lpython25 -lstdc++ 
INCS = -I"$(PYTHON_DIR)\include" -I".\src"

CFLAGS = $(INCS) -mno-cygwin -mdll -O -Wall
LDFLAGS = $(LIBS) -lc -mno-cygwin -static 
DWFLAGS = -mno-cygwin -mdll -static

#
OBJ  = foo.o number.o foo_wrap.o
SRC  = $(OBJ:.o=.cpp)
BIN  = $(MODULE_NAME).pyd
DEFFILE = $(MODULE_NAME).def
LIBFILE = lib$(MODULE_NAME).a

all: $(BIN)

clean:
	$(RM) $(OBJ) $(BIN) $(DEFFILE) $(LIBFILE) *.pyc src/foo_wrap.cpp foo.py

$(BIN): $(OBJ) $(DEFFILE)
	$(DLLWRAP) $(DWFLAGS) --output-lib $(LIBFILE) --def $(DEFFILE) -s $(OBJ) $(LIBS) -o $@

%.o: src/%.cpp
	$(CXX) -g -c $< -o $@ $(CFLAGS)


src/foo_wrap.cpp : src/foo.i
	swig -c++ -python -o $@ $< 

$(DEFFILE):
	@echo LIBRARY $(BIN)>$(DEFFILE)
	@echo EXPORTS >>$(DEFFILE)
#	@echo init$(MODULE_NAME)>>$(DEFFILE)
    
.PHONY : install
install:
	@cp -vf $(BIN) $(PYTHON_DIR)\Lib\site-packages
    
.PHONY : test
test:
	$(PYTHON_DIR)\python test.py
